<?php
namespace frontend\controllers;

use frontend\models\ArtForm;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\Response;
use yii\base\ErrorException;
use yii\helpers\Html;
use common\widgets\file_upload\FileUpload;
use common\models\member\Member;
use common\models\category\Category;
use common\models\articles\Articles;
use common\models\art\Art;
use common\models\meeting\Meeting;
use yii\data\Pagination;
use yii\web\Request;

class SearchController extends Controller
{     
	 public $layout = 'searchpage';
	public function actions()
    {
        return [
            'upload'=>[
                'class' => 'common\widgets\file_upload\UploadAction',     //这里扩展地址别写错
                'config' => [
                ]
            ],
			'ueditor'=>[
				'class' => 'common\widgets\ueditor\UeditorAction',
				'config'=>[
					//上传图片配置
					'imageUrlPrefix' => "", /* 图片访问路径前缀 */
					'imagePathFormat' => "/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
				]
			]
        ];
    }

    /**
    * 新闻列表 zsn 20161229
    */
  public function actionSearch(){
//andFilterCompare('name', 'Doe', 'like');

		  $keyword=Yii::$app->request->get()['keywords'];

	  $query = Articles::find()->andFilterCompare('title', $keyword, 'like')->andWhere(['status'=>10]);
	  $count = $query->count();
	  $page = new Pagination(['totalCount' => $count, 'pageSize' => '24']);
	  $articles = $query->offset($page->offset)
		    ->limit($page->limit)
		    ->all();
	  return $this->render('search',[
		  'keywords' => $keyword,
		  'count' => $count,
          'articles' => $articles,
          'page' => $page,
        ]);
  }
    /**
    * 新闻内页
    */
	public function actionSearchcontent($id){

		$article = Articles::find()->where(['id'=>$id])->one();
		$keywords = Yii::$app->request->get()['keywords'];
		$query = Articles::find()->andFilterCompare('title', $keywords, 'like')->andWhere(['status'=>10]);
		$count = $query->count();
   		return $this->render('searchcontent',[
   			'id' => $id,
			'count' => $count,
   			'article' => $article,
   			'keywords' => $keywords,

      ]);
  }


}